//
//  ViewController.swift
//  DecodableDemo
//
//  Created by 李煜 on 2024/4/18.
//

import UIKit

struct Person: Decodable {
    let name: String
    let age: Int
    let isStudent: Bool

    enum CodingKeys: String, CodingKey {
        case name
        case age
        case is_Student = "isStudent"
    }
    
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let jsonString = """
        {
        "name": "John",
        "age":30,
        "isStudent": false
        }
        """
        
        do {
            let decoder = JSONDecoder()
            
            let person = try decoder.decode(Person.self, from: jsonString.data(using: .utf8)!)
            debugPrint(person.name)
            debugPrint(person.age)
            debugPrint(person.isStudent)
        } catch  {

            debugPrint("error decoding JSON: \(error)")

            
        }
    }
}
